/**
 * Live GPS Tracking Application
 * Provides line-by-line access to an input stream
 *
 * Copyright 2009, Ivar Clemens
 */

package nl.ivarclemens;

import java.io.InputStream;
import java.io.ByteArrayOutputStream;

public class StringReader {
    InputStream is;
    ByteArrayOutputStream bs = new ByteArrayOutputStream();

    boolean canRead = true;

    public StringReader(InputStream is)
    {
        this.is = is;
    }

    public boolean finished()
    {
        return !canRead;
    }

    public String readString()
    {
        int ch;

        try {
            while((ch = is.read()) != -1) {
                if(ch == 13)
                    continue;

                if(ch == 10)
                    break;

                bs.write(ch);
            }

            if(ch == -1)
                canRead = false;

        } catch(Exception e) {
            canRead = false;
        }

        String tmp = bs.toString();
        bs.reset();

        return tmp;
    }
}
